<script lang="ts" setup name="LifeStyle">
import {onBeforeMount, reactive, ref, computed} from 'vue'
import useUser from '@/store/user'
import {getLifeStyle, LifeStyle, LifeStyleParams, rejectLifeStyle, saveLifeStyle} from '@/api/medicalExaminerDesk/beginPhysicalExamination/lifeStyle'
import {ElMessage, FormRules} from 'element-plus/es'
import {ChecksOrRadios, fieldRequired} from '@/api/medicalExaminerDesk/beginPhysicalExamination'
import {NotLeadingAndTrailingSpaces, Number_3, Number_4, Number_Decimal_4} from '@/util/common'
import {showMessageBox} from '@/util/element'
const user = useUser.setup().store

const props = defineProps({
  // 体检登记表id
  checkupRegisterId: {
    type: String,
    required: true,
    default: ''
  },
  // 禁止编辑
  disEdit: {
    type: Boolean,
    required: true,
    default: false
  },
  // 性别
  gender: {
    type: String,
    required: false,
    default: ''
  }
})

// 保存和拒检的加载
const showSaveLoading = ref<boolean>(false)

// 生活方式表单
const lifeStyleForm = reactive<LifeStyle>({
  exerFreqState: '4', // 锻炼频率
  exerMethod: '', // 锻炼方式
  eatHabit: '', //饮食习惯
  eatHabitRadio: '1',
  eatHabitCheckboxs: [],
  smokeState: '1', // 吸烟状况
  drinkFreqState: '1', // 饮酒频率
  drinkType: '', // 饮酒种类
  drinkTypeCheckboxs: [], // 饮酒种类复选
  drinkTypeOthers: '', // 饮酒种类其他
  occupaHist: '1', // 职业病危害因素接触史
  workTypeName: '', // 工种
  dust: '', // 毒物种类粉尘
  dustSecurity: '1', // 毒物种类粉尘防护措施
  dustSecurityExist: '', //毒物种类粉尘-有防护措施内容
  radi: '', // 毒物种类放射物质
  radiSecurity: '1', // 毒物种类放射物质防护措施
  radiSecurityExist: '', //毒物种类放射物质-有防护措施内容
  phys: '', // 毒物种类物理因素
  physSecurity: '1', // 毒物种类物理因素防护措施
  physSecurityExist: '', //毒物种类物理因素-有防护措施内容
  chem: '', // 毒物种类化学物质
  chemSecurity: '1', // 毒物种类化学物质防护措施
  chemSecurityExist: '', //毒物种类化学物质-有防护措施内容
  other: '', // 毒物种类其他
  otherSecurity: '1', // 毒物种类其他防护措施
  otherSecurityExist: '' //毒物种类其他-有防护措施内容
})

// 表单实例
const formRef = ref()

// 体检大类的体检医生姓名
const dutyDoctorName2 = computed(() => {
  return lifeStyleForm.dutyDoctorName || (user.userInfor?.jobName === '医生' ? user.userInfor?.userName : '')
})

// 体检状态
const checkupStatus2 = computed(() => {
  return lifeStyleForm.checkupStatus
})

// 锻炼频率
const exerFreqStateRadios: Array<ChecksOrRadios> = [
  {label: '每天', value: '1'},
  {label: '每周一次以上', value: '2'},
  {label: '偶尔', value: '3'},
  {label: '不锻炼', value: '4'}
]

// 吸烟状况
const smokeStateRadios: Array<ChecksOrRadios> = [
  {label: '从不吸烟', value: '1'},
  {label: '已戒烟', value: '2'},
  {label: '吸烟', value: '3'}
]

// 饮酒频率
const drinkFreqStateRadios: Array<ChecksOrRadios> = [
  {label: '从不', value: '1'},
  {label: '偶尔', value: '2'},
  {label: '经常', value: '3'},
  {label: '每天', value: '4'}
]

// 饮酒种类：
const drinkCheckboxs: Array<ChecksOrRadios> = [
  {label: '白酒', value: '1'},
  {label: '啤酒', value: '2'},
  {label: '红酒', value: '3'},
  {label: '黄酒', value: '4'},
  {label: '其他', value: '5'}
]

// 计算体育锻炼伪元素三角形位置
const exerFreqTriangleLeft = computed(() => {
  return (lifeStyleForm.exerFreqState === '1' ? 90 : lifeStyleForm.exerFreqState === '2' ? 200 : 320) + 'px'
})

// 计算吸烟情况伪元素三角形位置
const smokeStateLeft = computed(() => {
  return (lifeStyleForm.smokeState === '2' ? 210 : 300) + 'px'
})

// 计算饮酒情况伪元素三角形位置
const drinkFreqStateLeft = computed(() => {
  return (lifeStyleForm.drinkFreqState === '2' ? 180 : lifeStyleForm.drinkFreqState === '3' ? 260 : 340) + 'px'
})

// 吸烟年龄比较
const SmorkeAgeValid = (rule, value, callback) => {
  const startAge = lifeStyleForm.startSmorkeAge
  const quitAge = lifeStyleForm.quitSmorkeAge
  if (startAge && quitAge && Number(startAge) > Number(quitAge) && lifeStyleForm.smokeState === '2') {
    return callback(new Error('戒烟年龄不小于开始吸烟年龄!'))
  } else {
    return callback()
  }
}

// 喝酒年龄比较
const DrinkAgeValid = (rule, value, callback) => {
  const startAge = lifeStyleForm.startDrinkAge
  const quitAge = lifeStyleForm.quitDrinkAge
  if (startAge && quitAge && Number(startAge) > Number(quitAge) && lifeStyleForm.quitDrinkState === '2') {
    return callback(new Error('戒酒年龄不小于开始饮酒年龄!'))
  } else {
    return callback()
  }
}

// 毒物种类统一校验规则
const dustTypeRule = [
  {required: fieldRequired('dust'), message: '请输入毒物种类!', trigger: ['change', 'blur']},
  {pattern: NotLeadingAndTrailingSpaces, message: '首尾不能为空格！', trigger: ['change', 'blur']},
  {max: 50, message: '最多50个字符！', trigger: ['change', 'blur']}
]

// 防护措施统一校验规则
const securityExistRule = [
  {required: fieldRequired('dustSecurityExist'), message: '请输入防护措施!', trigger: ['change', 'blur']},
  {pattern: NotLeadingAndTrailingSpaces, message: '首尾不能为空格！', trigger: ['change', 'blur']},
  {max: 50, message: '最多50个字符！', trigger: ['change', 'blur']}
]

// 表单校验规则
const rules = computed<FormRules>(() => {
  return {
    // 体育锻炼
    exerFreqState: [{required: fieldRequired('exerFreqState'), message: '请选择锻炼频率!', trigger: ['change', 'blur']}],
    // 每次锻炼时间
    perExerTime: [
      {required: fieldRequired('perExerTime'), message: '请输入每次锻炼时间!', trigger: ['change', 'blur']},
      {pattern: Number_4, message: '最多四个数字!', trigger: ['change', 'blur']}
    ],
    // 坚持锻炼时间
    insExerTime: [
      {required: fieldRequired('insExerTime'), message: '请输入坚持锻炼时间!', trigger: ['change', 'blur']},
      {pattern: Number_Decimal_4, message: '最多四个数字，包括一位小数!', trigger: ['change', 'blur']}
    ],
    // 锻炼方式
    exerMethod: [
      {required: fieldRequired('exerMethod'), message: '请输入锻炼方式!', trigger: ['change', 'blur']},
      {pattern: NotLeadingAndTrailingSpaces, message: '首尾不能为空格！', trigger: ['change', 'blur']},
      {max: 100, message: '最多100个字符！', trigger: ['change', 'blur']}
    ],
    // 饮食习惯
    eatHabitRadio: [{required: fieldRequired('eatHabit'), message: '请选择饮食习惯!', trigger: ['change', 'blur']}],
    // 吸烟情况
    smokeState: [{required: fieldRequired('smokeState'), message: '请选择吸烟情况!', trigger: ['change', 'blur']}],
    // 日吸烟量
    dailySmokeSum: [
      {required: fieldRequired('dailySmokeSum'), message: '请输入日吸烟量!', trigger: ['change', 'blur']},
      {pattern: Number_3, message: '最多三个数字！', trigger: ['change', 'blur']}
    ],
    // 开始吸烟年龄
    startSmorkeAge: [
      {required: fieldRequired('startSmorkeAge'), message: '请输入开始吸烟年龄!', trigger: ['change', 'blur']},
      {pattern: Number_3, message: '最多三个数字！', trigger: ['change', 'blur']},
      {validator: SmorkeAgeValid, trigger: ['change', 'blur']}
    ],
    // 戒烟年龄
    quitSmorkeAge: [
      {required: fieldRequired('quitSmorkeAge'), message: '请输入戒烟年龄!', trigger: ['change', 'blur']},
      {pattern: Number_3, message: '最多三个数字！', trigger: ['change', 'blur']},
      {validator: SmorkeAgeValid, trigger: ['change', 'blur']}
    ],
    // 饮酒情况
    drinkFreqState: [{required: fieldRequired('drinkFreqState'), message: '请选择饮酒情况!', trigger: ['change', 'blur']}],
    // 日饮酒量
    dailyDrinkSum: [
      {required: fieldRequired('dailyDrinkSum'), message: '请输入日饮酒量!', trigger: ['change', 'blur']},
      {pattern: Number_3, message: '最多三个数字！', trigger: ['change', 'blur']}
    ],
    // 是否戒酒
    quitDrinkState: [{required: fieldRequired('quitDrinkState'), message: '请勾选是否戒酒!', trigger: ['change', 'blur']}],
    // 戒酒年龄
    quitDrinkAge: [
      {required: fieldRequired('quitDrinkAge'), message: '请输入戒酒年龄!', trigger: ['change', 'blur']},
      {pattern: Number_3, message: '最多三个数字！', trigger: ['change', 'blur']},
      {validator: DrinkAgeValid, trigger: ['change', 'blur']}
    ],
    // 开始饮酒年龄
    startDrinkAge: [
      {required: fieldRequired('startDrinkAge'), message: '请输入开始饮酒年龄!', trigger: ['change', 'blur']},
      {pattern: Number_3, message: '最多三个数字！', trigger: ['change', 'blur']},
      {validator: DrinkAgeValid, trigger: ['change', 'blur']}
    ],
    // 近一年是否曾醉酒
    drunkState: [{required: fieldRequired('drunkState'), message: '请勾选是否曾醉酒!', trigger: ['change', 'blur']}],
    // 饮酒种类
    drinkTypeCheckboxs: [{required: fieldRequired('drinkType'), type: 'array', message: '请勾选饮酒种类!', trigger: ['change', 'blur']}],
    // 饮酒种类其他
    drinkTypeOthers: [
      {pattern: NotLeadingAndTrailingSpaces, message: '首尾不能为空格！', trigger: ['change', 'blur']},
      {max: 20, message: '最多20个字符！', trigger: ['change', 'blur']}
    ],
    // 职业病危害因素接触史
    occupaHist: [{required: fieldRequired('occupaHist'), message: '请选择职业病危害因素接触史!', trigger: ['change', 'blur']}],
    // 工种
    workTypeName: [
      {required: fieldRequired('workTypeName'), message: '请输入工种!', trigger: ['change', 'blur']},
      {pattern: NotLeadingAndTrailingSpaces, message: '首尾不能为空格！', trigger: ['change', 'blur']},
      {max: 50, message: '最多50个字符！', trigger: ['change', 'blur']}
    ],
    // 从业时间
    ageLimit: [
      {required: fieldRequired('ageLimit'), message: '请输入从业时间!', trigger: ['change', 'blur']},
      {pattern: Number_Decimal_4, message: '最多四个数字，包括一位小数!', trigger: ['change', 'blur']}
    ],
    // 毒物种类(其他种类都以粉尘为准)
    dust: dustTypeRule,
    // 防护措施(其他种类都以粉尘为准)
    dustSecurityExist: securityExistRule,
    radi: dustTypeRule, // 毒物种类放射物质
    radiSecurityExist: securityExistRule, //毒物种类放射物质-有防护措施内容
    phys: dustTypeRule, // 毒物种类物理因素
    physSecurityExist: securityExistRule, //毒物种类物理因素-有防护措施内容
    chem: dustTypeRule, // 毒物种类化学物质
    chemSecurityExist: securityExistRule, //毒物种类化学物质-有防护措施内容
    other: dustTypeRule, // 毒物种类其他
    otherSecurityExist: securityExistRule //毒物种类其他-有防护措施内容
  }
})

/**
 * @description: 获取体检信息
 * @return {*}
 */
const getInitData = () => {
  props.checkupRegisterId &&
    getLifeStyle(props.checkupRegisterId)
      .then((res) => {
        const {data} = res.data
        data?.dailySmokeSum && (data.dailySmokeSum = Number(data?.dailySmokeSum) || undefined) // 转数字
        // 浅拷贝
        Object.assign(lifeStyleForm, data)
        // 饮食习惯数据处理
        lifeStyleForm.eatHabitRadio =
          data?.eatHabit?.split('|')?.filter((item) => {
            return item !== '' // 去掉空串脏数据
          })[0] || '1' // 饮食习惯单选
        lifeStyleForm.eatHabitCheckboxs = data?.eatHabit?.split('|').slice(1) || [] // 饮食习惯多选
        lifeStyleForm.drinkTypeCheckboxs =
          data?.drinkType?.split('|')?.filter((item) => {
            return item !== '' // 去掉空串脏数据
          }) || []
        // 处理初始化的空数据
        !lifeStyleForm.exerFreqState && (lifeStyleForm.exerFreqState = '4')
        !lifeStyleForm.smokeState && (lifeStyleForm.smokeState = '1')
        !lifeStyleForm.drinkFreqState && (lifeStyleForm.drinkFreqState = '1')
        !lifeStyleForm.occupaHist && (lifeStyleForm.occupaHist = '1')
        !lifeStyleForm.dustSecurity && (lifeStyleForm.dustSecurity = '1')
        !lifeStyleForm.radiSecurity && (lifeStyleForm.radiSecurity = '1')
        !lifeStyleForm.physSecurity && (lifeStyleForm.physSecurity = '1')
        !lifeStyleForm.chemSecurity && (lifeStyleForm.chemSecurity = '1')
        !lifeStyleForm.otherSecurity && (lifeStyleForm.otherSecurity = '1')
      })
      .finally(() => {
        showSaveLoading.value = false
      })
}

// 表单参数
const formDataParams = computed<LifeStyleParams>(() => {
  return {
    exerFreqState: lifeStyleForm.exerFreqState, // 锻炼频率
    perExerTime: lifeStyleForm.exerFreqState !== '4' ? lifeStyleForm.perExerTime : undefined, // 每次锻炼时间
    insExerTime: lifeStyleForm.exerFreqState !== '4' ? lifeStyleForm.insExerTime : undefined, // 坚持锻炼时间
    exerMethod: lifeStyleForm.exerFreqState !== '4' ? lifeStyleForm.exerMethod : undefined, // 锻炼方式
    eatHabit: lifeStyleForm.eatHabitRadio + `${lifeStyleForm.eatHabitCheckboxs?.length ? '|' : ''}${lifeStyleForm.eatHabitCheckboxs?.join('|')}`, //饮食习惯
    smokeState: lifeStyleForm.smokeState, // 吸烟状况
    dailySmokeSum: lifeStyleForm.smokeState !== '1' ? lifeStyleForm.dailySmokeSum : undefined, // 平均日吸烟量
    startSmorkeAge: lifeStyleForm.smokeState !== '1' ? lifeStyleForm.startSmorkeAge : undefined, // 开始吸烟年龄
    quitSmorkeAge: lifeStyleForm.smokeState === '2' ? lifeStyleForm.quitSmorkeAge : undefined, // 戒烟年龄
    drinkFreqState: lifeStyleForm.drinkFreqState, // 饮酒频率
    dailyDrinkSum: lifeStyleForm.drinkFreqState !== '1' ? lifeStyleForm.dailyDrinkSum : undefined, // 日饮酒量
    quitDrinkState: lifeStyleForm.drinkFreqState !== '1' ? lifeStyleForm.quitDrinkState : undefined, // 是否戒酒
    quitDrinkAge: lifeStyleForm.quitDrinkAge, // 戒酒年龄
    startDrinkAge: lifeStyleForm.drinkFreqState !== '1' ? lifeStyleForm.startDrinkAge : undefined, //开始饮酒年龄
    drunkState: lifeStyleForm.drinkFreqState !== '1' ? lifeStyleForm.drunkState : undefined, // 近一年是否曾醉酒
    drinkType: lifeStyleForm.drinkFreqState !== '1' ? lifeStyleForm.drinkTypeCheckboxs.join('|') : null, // 饮酒种类
    drinkTypeOthers: lifeStyleForm.drinkTypeCheckboxs?.indexOf('5') !== -1 ? lifeStyleForm.drinkTypeOthers : null, // 饮酒种类其他
    occupaHist: lifeStyleForm.occupaHist, // 职业病危害因素接触史
    workTypeName: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.workTypeName : null, // 工种
    ageLimit: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.ageLimit : undefined, // 从业时间
    dust: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.dust : null, // 毒物种类粉尘
    dustSecurity: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.dustSecurity : '1', // 毒物种类粉尘防护措施
    dustSecurityExist: lifeStyleForm.dustSecurity === '2' && lifeStyleForm.occupaHist === '2' ? lifeStyleForm.dustSecurityExist : null, //毒物种类粉尘-有防护措施内容
    radi: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.radi : null, // 毒物种类放射物质
    radiSecurity: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.radiSecurity : '1', // 毒物种类放射物质防护措施
    radiSecurityExist: lifeStyleForm.radiSecurity === '2' && lifeStyleForm.occupaHist === '2' ? lifeStyleForm.radiSecurityExist : null, //毒物种类放射物质-有防护措施内容
    phys: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.phys : null, // 毒物种类物理因素
    physSecurity: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.physSecurity : '1', // 毒物种类物理因素防护措施
    physSecurityExist: lifeStyleForm.physSecurity === '2' && lifeStyleForm.occupaHist === '2' ? lifeStyleForm.physSecurityExist : null, //毒物种类物理因素-有防护措施内容
    chem: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.chem : null, // 毒物种类化学物质
    chemSecurity: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.chemSecurity : '1', // 毒物种类化学物质防护措施
    chemSecurityExist: lifeStyleForm.chemSecurity === '2' && lifeStyleForm.occupaHist === '2' ? lifeStyleForm.chemSecurityExist : null, //毒物种类化学物质-有防护措施内容
    other: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.other : null, // 毒物种类其他
    otherSecurity: lifeStyleForm.occupaHist === '2' ? lifeStyleForm.otherSecurity : '1', // 毒物种类其他防护措施
    otherSecurityExist: lifeStyleForm.otherSecurity === '2' && lifeStyleForm.occupaHist === '2' ? lifeStyleForm.otherSecurityExist : null //毒物种类其他-有防护措施内容
  }
})

/**
 * @description: 保存
 * @return {*}
 */
const onSave2 = () => {
  formRef.value &&
    formRef.value.validate((valid: boolean, fields) => {
      if (valid) {
        showSaveLoading.value = true
        const params = {
          ...formDataParams.value,
          checkupStatus: 2, // 已检
          id: lifeStyleForm.id, // 表单Id
          checkupRegisterId: props.checkupRegisterId, // 体检登记表id
          dutyDoctorId: lifeStyleForm.dutyDoctorId || user.userInfor?.id, // 体检医生id
          dutyDoctorName: lifeStyleForm.dutyDoctorId !== user.userInfor?.id ? lifeStyleForm.dutyDoctorName || user.userInfor?.userName : user.userInfor?.userName // 体检医生姓名
        }
        saveLifeStyle(params)
          .then(() => {
            getInitData()
            ElMessage.success('保存成功!')
          })
          .catch((err) => {
            console.warn(err)
            showSaveLoading.value = false
          })
      } else {
        console.warn(fields)
      }
    })
}

/**
 * @description: 拒检
 * @return {*}
 */
const onRejectInspection2 = () => {
  showMessageBox('是否对该体检大类进行拒检操作？', {title: '拒检确认', mesageType: 'base'})
    .then(() => {
      showSaveLoading.value = true
      const nullParams: LifeStyleParams = {...formDataParams.value}
      // 置空
      Object.keys(formDataParams.value)?.forEach((item) => {
        nullParams[item] = null
      })
      const params = {
        ...nullParams,
        checkupStatus: 1, // 1拒检
        id: lifeStyleForm.id, // 表单Id
        checkupRegisterId: props.checkupRegisterId, // 体检登记表id
        dutyDoctorId: lifeStyleForm.dutyDoctorId || user.userInfor?.id, // 体检医生id
        dutyDoctorName: lifeStyleForm.dutyDoctorId !== user.userInfor?.id ? lifeStyleForm.dutyDoctorName || user.userInfor?.userName : user.userInfor?.userName // 体检医生姓名
      }
      rejectLifeStyle(params)
        .then(() => {
          ElMessage.success('拒检成功!')
          getInitData()
        })
        .catch((error) => {
          showSaveLoading.value = false
          console.warn(error)
        })
    })
    .catch((error) => {
      console.warn(error)
    })
}

onBeforeMount(() => {
  getInitData()
})
</script>
<template>
  <el-form ref="formRef" class="d-check-up-desk-content" label-position="top" :model="lifeStyleForm" :rules="rules" :disabled="disEdit">
    <el-form-item label="体育锻炼" prop="exerFreqState" class="life-style-form-item">
      <span>锻炼频率：</span>
      <el-radio-group v-model="lifeStyleForm.exerFreqState">
        <el-radio v-for="item in exerFreqStateRadios" :key="item.value" :label="item.value">
          {{ item.label }}
        </el-radio>
      </el-radio-group>
      <div v-if="lifeStyleForm.exerFreqState !== '4'" class="inline-input-number-item poison-type exerFreq-triangle d-common-width-full">
        <el-form-item label="每次锻炼时间" prop="perExerTime">
          <el-input-number v-model="lifeStyleForm.perExerTime" :controls="false" />分钟
        </el-form-item>
        <el-form-item label="坚持锻炼时间" prop="insExerTime">
          <el-input-number v-model="lifeStyleForm.insExerTime" :controls="false" />年
        </el-form-item>
        <el-form-item label="锻炼方式" prop="exerMethod">
          <el-input v-model="lifeStyleForm.exerMethod" size="small" clearable style="width: 300px" />
        </el-form-item>
      </div>
    </el-form-item>
    <el-form-item label="饮食习惯" prop="eatHabitRadio" class="life-style-form-item">
      <el-radio-group v-model="lifeStyleForm.eatHabitRadio" style="margin-right: 40px">
        <el-radio label="1">
          荤素均衡
        </el-radio>
        <el-radio label="2">
          荤食为主
        </el-radio>
        <el-radio label="3">
          素食为主
        </el-radio>
      </el-radio-group>
      <el-checkbox-group v-model="lifeStyleForm.eatHabitCheckboxs">
        <el-checkbox label="4">
          嗜盐
        </el-checkbox>
        <el-checkbox label="5">
          嗜油
        </el-checkbox>
        <el-checkbox label="6">
          嗜糖
        </el-checkbox>
      </el-checkbox-group>
    </el-form-item>
    <el-form-item label="吸烟情况" prop="smokeState" class="life-style-form-item">
      <span>吸烟状况：</span>
      <el-radio-group v-model="lifeStyleForm.smokeState">
        <el-radio v-for="item in smokeStateRadios" :key="item.value" :label="item.value">
          {{ item.label }}
        </el-radio>
      </el-radio-group>
      <div v-if="lifeStyleForm.smokeState !== '1'" class="inline-input-number-item poison-type smokeState-triangle d-common-width-full">
        <el-form-item label="日吸烟量" prop="dailySmokeSum">
          平均<el-input-number v-model="lifeStyleForm.dailySmokeSum" :controls="false" />支
        </el-form-item>
        <el-form-item label="开始吸烟年龄" prop="startSmorkeAge">
          <el-input-number v-model="lifeStyleForm.startSmorkeAge" :controls="false" @change="formRef?.validateField(['startSmorkeAge', 'quitSmorkeAge'])" />岁
        </el-form-item>
        <el-form-item v-if="lifeStyleForm.smokeState === '2'" label="戒烟年龄" prop="quitSmorkeAge">
          <el-input-number v-model="lifeStyleForm.quitSmorkeAge" :controls="false" @change="formRef?.validateField(['startSmorkeAge', 'quitSmorkeAge'])" />岁
        </el-form-item>
      </div>
    </el-form-item>
    <el-form-item label="饮酒情况" prop="drinkFreqState" class="life-style-form-item">
      <div class="d-common-flex-col d-common-width-full">
        <div>
          <span>饮酒频率：</span>
          <el-radio-group v-model="lifeStyleForm.drinkFreqState">
            <el-radio v-for="item in drinkFreqStateRadios" :key="item.value" :label="item.value">
              {{ item.label }}
            </el-radio>
          </el-radio-group>
        </div>
        <div v-if="lifeStyleForm.drinkFreqState !== '1'" class="drink-freq-state-infor">
          <el-row>
            <el-form-item label="日饮酒量" prop="dailyDrinkSum" class="inline-input-number-item d-common-flex-row">
              平均<el-input-number v-model="lifeStyleForm.dailyDrinkSum" :controls="false" />两
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="是否戒酒" prop="quitDrinkState" class="inline-input-number-item d-common-flex-row">
              <el-radio-group v-model="lifeStyleForm.quitDrinkState">
                <el-radio label="1">
                  未戒酒
                </el-radio>
                <el-radio label="2">
                  已戒酒
                </el-radio>
              </el-radio-group>
              <el-form-item v-if="lifeStyleForm.quitDrinkState === '2'" prop="quitDrinkAge" label="戒酒年龄" style="margin-left: 25px">
                <el-input-number v-model="lifeStyleForm.quitDrinkAge" :controls="false" @change="formRef?.validateField(['quitDrinkAge', 'startDrinkAge'])" />岁
              </el-form-item>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="开始饮酒年龄" prop="startDrinkAge" class="inline-input-number-item d-common-flex-row">
              <el-input-number v-model="lifeStyleForm.startDrinkAge" :controls="false" @change="formRef?.validateField(['quitDrinkAge', 'startDrinkAge'])" />岁
            </el-form-item>
            <el-form-item label="近一年是否曾醉酒" prop="drunkState" class="inline-input-number-item d-common-flex-row">
              <el-radio-group v-model="lifeStyleForm.drunkState">
                <el-radio label="1">
                  是
                </el-radio>
                <el-radio label="2">
                  否
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-row>
          <el-form-item label="饮酒种类" prop="drinkTypeCheckboxs" class="inline-input-number-item d-common-flex-row">
            <el-checkbox-group v-model="lifeStyleForm.drinkTypeCheckboxs">
              <el-checkbox v-for="item in drinkCheckboxs" :key="item.value" :label="item.value">
                {{ item.label }}
              </el-checkbox>
            </el-checkbox-group>
            <el-form-item v-if="lifeStyleForm.drinkTypeCheckboxs.indexOf('5') !== -1" prop="drinkTypeOthers">
              <el-input v-model="lifeStyleForm.drinkTypeOthers" size="small" clearable style="width: 300px" />
            </el-form-item>
          </el-form-item>
        </div>
      </div>
    </el-form-item>
    <el-form-item label="职业病危害因素接触史" prop="occupaHist" class="life-style-form-item">
      <div class="inline-input-number-item d-common-flex-row d-common-width-full">
        <el-radio-group v-model="lifeStyleForm.occupaHist" style="margin-right: 40px">
          <el-radio label="1">
            无
          </el-radio>
          <el-radio label="2">
            有
          </el-radio>
        </el-radio-group>
        <div v-if="lifeStyleForm.occupaHist === '2'" class="work-type-form">
          <el-form-item prop="workTypeName" label="工种：">
            <el-input v-model="lifeStyleForm.workTypeName" clearable />
          </el-form-item>
          <el-form-item prop="ageLimit" label="从业时间：">
            <el-input-number v-model="lifeStyleForm.ageLimit" :controls="false" />年
          </el-form-item>
        </div>
      </div>
      <div v-if="lifeStyleForm.occupaHist === '2'" class="inline-input-number-item poison-type occupaHist-triangle d-common-width-full">
        毒物种类
        <el-divider />
        <div class="inline-form">
          <el-row>
            <el-form-item prop="dust" label="粉尘">
              <el-input v-model="lifeStyleForm.dust" clearable />
            </el-form-item>
            <el-form-item prop="dustSecurityExist" label="防护措施">
              <el-radio-group v-model="lifeStyleForm.dustSecurity">
                <el-radio label="1">
                  无
                </el-radio>
                <el-radio label="2">
                  有
                </el-radio>
              </el-radio-group>
              <el-input v-if="lifeStyleForm.dustSecurity === '2'" v-model="lifeStyleForm.dustSecurityExist" clearable class="dust-exist" />
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="radi" label="放射物质">
              <el-input v-model="lifeStyleForm.radi" clearable />
            </el-form-item>
            <el-form-item prop="radiSecurityExist" label="防护措施">
              <el-radio-group v-model="lifeStyleForm.radiSecurity">
                <el-radio label="1">
                  无
                </el-radio>
                <el-radio label="2">
                  有
                </el-radio>
              </el-radio-group>
              <el-input v-if="lifeStyleForm.radiSecurity === '2'" v-model="lifeStyleForm.radiSecurityExist" clearable class="dust-exist" />
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="phys" label="物理因素">
              <el-input v-model="lifeStyleForm.phys" clearable />
            </el-form-item>
            <el-form-item prop="physSecurityExist" label="防护措施">
              <el-radio-group v-model="lifeStyleForm.physSecurity">
                <el-radio label="1">
                  无
                </el-radio>
                <el-radio label="2">
                  有
                </el-radio>
              </el-radio-group>
              <el-input v-if="lifeStyleForm.physSecurity === '2'" v-model="lifeStyleForm.physSecurityExist" clearable class="dust-exist" />
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="chem" label="化学物质">
              <el-input v-model="lifeStyleForm.chem" clearable />
            </el-form-item>
            <el-form-item prop="chemSecurityExist" label="防护措施">
              <el-radio-group v-model="lifeStyleForm.chemSecurity">
                <el-radio label="1">
                  无
                </el-radio>
                <el-radio label="2">
                  有
                </el-radio>
              </el-radio-group>
              <el-input v-if="lifeStyleForm.chemSecurity === '2'" v-model="lifeStyleForm.chemSecurityExist" clearable class="dust-exist" />
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item prop="other" label="其他">
              <el-input v-model="lifeStyleForm.other" clearable />
            </el-form-item>
            <el-form-item prop="otherSecurityExist" label="防护措施">
              <el-radio-group v-model="lifeStyleForm.otherSecurity">
                <el-radio label="1">
                  无
                </el-radio>
                <el-radio label="2">
                  有
                </el-radio>
              </el-radio-group>
              <el-input v-if="lifeStyleForm.otherSecurity === '2'" v-model="lifeStyleForm.otherSecurityExist" clearable class="dust-exist" />
            </el-form-item>
          </el-row>
        </div>
      </div>
    </el-form-item>
  </el-form>
  <div class="d-check-up-desk-footer d-common-flex-center d-common-width-full">
    <span class="doctor">体检医生：</span>
    <el-input v-model="dutyDoctorName2" disabled />
    <el-button type="primary" :loading="showSaveLoading" :disabled="disEdit" @click="onSave2()">
      保存
    </el-button>
    <el-button type="danger" :loading="showSaveLoading" :disabled="(checkupStatus2 && checkupStatus2 === 1) || disEdit" plain @click="onRejectInspection2()">
      拒检
    </el-button>
  </div>
</template>
<style scoped lang="less">
.life-style-form-item {
  padding-bottom: 24px;
  margin-bottom: 19px;
  border-bottom: 1px solid rgba(195, 201, 210, 1);
  &:last-child {
    border-bottom: none;
  }
  :deep(.el-form-item__label) {
    color: var(--d-font-color-text);
    font-weight: bold;
    display: inline-flex;
    align-items: center;
  }
  :deep(.el-form-item__content) {
    margin-left: 23px;
  }
}
.inline-input-number-item {
  flex-wrap: nowrap;
  :deep(.el-form-item__label) {
    font-weight: normal;
    margin: 0 !important;
  }
  :deep(.el-form-item__content) {
    margin: 0;
  }
  .el-input-number,
  .el-input {
    width: 100px;
    height: 32px;
    margin: 0 5px;
  }
}
.drink-freq-state-infor {
  .el-row {
    margin-bottom: 15px;
  }
  .el-form-item {
    display: inline-flex;
    vertical-align: middle;
    margin-right: 60px;
  }
  background: #f4f4f4;
  border-radius: 4px;
  padding: 17px 14px 17px 30px;
  &::before {
    content: '';
    position: absolute;
    top: 24px;
    left: v-bind(drinkFreqStateLeft);
    border-right: solid 10px transparent;
    border-left: solid 10px transparent;
    border-bottom: solid 10px #f4f4f4;
  }
}
.poison-type {
  display: inline-flex;
  flex-wrap: wrap;
  .el-form-item {
    display: inline-flex;
    vertical-align: middle;
    margin-right: 60px;
    margin-bottom: 15px;
  }
  background: #f4f4f4;
  border-radius: 4px;
  margin-top: 10px;
  padding: 13px 25px 25px 16px;
  .el-divider {
    margin: 5px 0 13px 0;
  }
}
.dust-exist {
  width: 300px !important;
  margin-left: 15px !important;
}
.dust-exist + :deep(.el-form-item__error) {
  left: 50%;
}

.inline-form {
  .el-form-item {
    display: inline-flex;
    vertical-align: middle;
    margin-bottom: 15px;
  }
  :deep(.el-form-item__label) {
    width: 80px;
  }
}
.work-type-form {
  .el-form-item {
    display: inline-flex;
    vertical-align: middle;
  }
  :deep(.el-form-item__label) {
    width: 100px;
  }
}
.exerFreq-triangle {
  &::before {
    content: '';
    position: absolute;
    top: 32px;
    left: v-bind(exerFreqTriangleLeft);
    border-right: solid 10px transparent;
    border-left: solid 10px transparent;
    border-bottom: solid 10px #f4f4f4;
  }
}
.smokeState-triangle {
  &::before {
    content: '';
    position: absolute;
    top: 32px;
    left: v-bind(smokeStateLeft);
    border-right: solid 10px transparent;
    border-left: solid 10px transparent;
    border-bottom: solid 10px #f4f4f4;
  }
}
.occupaHist-triangle {
  &::before {
    content: '';
    position: absolute;
    top: 34px;
    left: 88px;
    border-right: solid 10px transparent;
    border-left: solid 10px transparent;
    border-bottom: solid 10px #f4f4f4;
  }
}
</style>
